$(function () {

    $("#searchProduct").on('keyup',function () {
        $("[name='autoSearch']").remove();
        $("[name='quickSearch']").append("<ul name = \"autoSearch\" id = \"autoSearch\" >quick search:</ul>");

        var searchName = $("[name='keyword']").val();

        if(searchName.trim() != ""){

            var queryString = "searchName=" + searchName;
            $.get("SearchProductAutoFill",queryString,function (data) {
                var responseString = data;
                var start = 0;
                var end = 0;
                var everyString;
                var index =0;
                var nameLe;
                var joke;

                for(var i=0;i<responseString.length;i++){
                    var now = responseString[i];
                    index = 0;

                    //分隔符
                    if(now == "|"){
                        end = i;
                        nameLe = "omg" + i;
                        everyString = responseString.substring(start,end);
                        $("[name='autoSearch']").append("<br>"+"<a " + "id=" + nameLe + " >"+ everyString + "</a>");
                        start = end+1;
                        // $("#omg").setAttribute("name",everyString);
                        // $("#omg").setAttribute("value",everyString);

                        joke = document.getElementById(nameLe);
                        if(joke == null)
                            alert("null");

                        joke.setAttribute("name",everyString);
                        joke.setAttribute("value",everyString);
                        joke.setAttribute("href","ChangeProductInputServlet?value=" + everyString);
                    }
                }
            })

        }

    })

})